﻿using System;
using System.Collections.Generic;
using System.Text;
using FunctionalCLR.Core;
using FunctionalCLR.Shell.Function.Mathematics;

namespace FunctionalCLR.Shell.Function {
    public class AverageNode : FuncNode {

        public AverageNode()
            : base() {
            this.Precedence = 0;
            base.Value = "average";
        }

        public override FuncNode GetReversedFunction(int index) {
            throw new NotImplementedException();
        }

        public override object Evaluate() {
            int index = 0;
            double[] d = new double[this.Children.Count];
            foreach (Node child in this.Children) {
                d[index++] = Convert.ToDouble(
                    child.Evaluate());
            }

            return StatisticsCore.Average(d).ToString();
        }
    }
}
